package com.lanou.renrenxin.tools;

import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMConversation;

/**
 * Created by zouhui on 16/3/15.
 */
public class ChatLogger {
    private String username;
    private EMConversation conversation;

    public ChatLogger(String username) {
        this.username = username;
        conversation = EMChatManager.getInstance().getConversation(username);
    }

    /**
     * //删除和某个user的整个的聊天记录(包括本地)
     */
    public void deleteOneLogger(){
        //删除和某个user的整个的聊天记录(包括本地)
        EMChatManager.getInstance().deleteConversation(username);
    }
    /**
     * 删除当前会话的某条聊天记录
     */
    public void deleteSingleLogger(String msgId) {
        conversation.removeMessage(msgId);
    }

    /**
     * 获取未读消息数量
     * @return
     */
    public int unreadNumber() {
        return conversation.getUnreadMsgCount();
    }

    /**
     * 未读消息数清零(指定会话消息未读数清零)
     */
    public void clearunReadMsg() {
        conversation.markAllMessagesAsRead();
    }

    /**
     * 所有未读消息数清零
     */
    public void clearAllUnreadMsg() {
        EMChatManager.getInstance().markAllConversationsAsRead();
    }

    /**
     * 获取消息总数
     * @return
     */
    public int getMsgCount() {
        return conversation.getMsgCount();
    }

    /**
     * 清空和某个user的聊天记录(包括本地)，不删除conversation这个会话对象
     */
    public void deleteOneConversationLogger() {
        EMChatManager.getInstance().clearConversation(username);
    }

    /**
     * 删除所有聊天记录
     */
    public void deleteAllLogger(){
        EMChatManager.getInstance().deleteAllConversation();
    }

    /**
     * 设置某条消息为已读
     */
    public void readMsg(String msgid){
        conversation.getMessage(msgid,true);
    }
}
